package com.hk.housekeeping.order.controller.item;

import com.hk.housekeeping.order.entity.OrderItem;
import com.hk.housekeeping.order.service.impl.ItemPageServImpl;
import com.hk.housekeeping.order.utils.PageUtils;
import com.hk.housekeeping.order.utils.ResponseCode;
import com.hk.housekeeping.order.utils.ResponseEntity;
import com.hk.housekeeping.order.utils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/item/page")
public class ItemPageController extends HttpServlet {
    private ItemPageServImpl itemPageServ = new ItemPageServImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String sid = req.getParameter("sid");
        int page = Integer.parseInt(req.getParameter("page"));
        int pageSize = Integer.parseInt(req.getParameter("pageSize"));

        ResponseEntity<PageUtils<List<OrderItem>>> entity = null;
        //调用业务逻辑
        try {
            PageUtils<List<OrderItem>> itemPage = itemPageServ.getItemPageList(sid, page, pageSize);
            entity = ResponseEntity.success(itemPage);
        } catch (SQLException throwables) {
            entity = ResponseEntity.error(ResponseCode.ITEM_DATA_GET_ERROR);
        }

        ResponseUtils.deliver(resp, entity);
    }
}
